<template>
  <div class="bankContainer">
    <!--搜索条件区域-->
    <div
      v-show="$route.name === 'personal'"
      class="personalSearch"
      style="margin-bottom: -5px"
    >
      <el-row>
        <!--<el-col :span="2">-->
        <!--<div class="grid-content bg-purple searchInputStyle">查询条件：</div>-->
        <!--</el-col>-->
        <el-col :lg="15" :md="20">
          <div class="grid-content bg-purple-light" style="margin-left: 2px">
            <avue-form
              ref="formPersonal"
              v-model="objForm"
              :option="optionFormData"
              @submit="searchSubmitForm"
            />
          </div>
        </el-col>
        <el-col :lg="7" :md="24">
          <div class="grid-content bg-purple">
            <el-button type="primary" @click="customerInquiry()"
              >客户查询</el-button
            >

            <el-button type="primary" @click="fourelementsProcess()"
              >四要素核身</el-button
            >

            <el-button type="primary" @click="verificationFn(0)"
              >密码验证</el-button
            >
            <el-button type="primary" @click="verificationFn(1)"
              >短信验证</el-button
            >
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="verificationTips">
      <span
        :class="{
          'el-icon-circle-close': this.idPass,
          'color-red': this.idPass,
          'el-icon-circle-check': !this.idPass,
          'color-green': !this.idPass,
        }"
        >{{ this.idCheckTxt }}</span
      >
    </div>
    <!-- 客户信息 -->
    <informationShow :data="personalInfoData" :option="personalOption" />
    <!-- 面包屑导航 -->
    <el-breadcrumb
      v-show="$route.name !== 'personal'"
      separator-class="el-icon-arrow-right"
      style="padding-left: 0px"
    >
      <el-breadcrumb-item :to="{ name: 'personal' }"
        >个人业务</el-breadcrumb-item
      >
      <el-breadcrumb-item
        v-if="$route.name === 'bussDetail' || $route.name === 'unBussDetail'"
        :to="{ name: 'customeBuss' }"
        >借据信息</el-breadcrumb-item
      >

      <el-breadcrumb-item>{{ $route.meta.aliasName }}</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 子模块区域 -->
    <div v-show="$route.name === 'personal'" class="sonArea mt10">
      <draggable v-model="listData" @start="drag = true" @end="drag = false">
        <div
          v-for="(item, index) in listData"
          v-if="item.show"
          :key="index"
          class="inlineStyle"
        >
          <div @click="goCreditList(item.routerName)">
            <div :class="[item.imgClass, 'commonIcon']" alt />
            <span>{{ item.name }}</span>
          </div>
        </div>
      </draggable>
    </div>

    <!-- 子模块路由展示 -->
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" />
  </div>
</template>
<script>
import informationShow from "@/components/common/informationShow";
import searchInput from "@/components/common/CommonDate";
import ChildDropDown from "@/components/common/DropDownLoad";
import draggable from "vuedraggable";
import { queryInfo, sendCode, queryCustomerLaonData } from "@/api/interface";

import axios from "axios";
export default {
  components: {
    // 客户信息展示
    informationShow,
    searchInput,
    ChildDropDown,
    draggable,
  },
  data() {
    const _that = this;
    // 手机号验证
    const validatePhone = function (rule, value, callback) {
      const phoneReg =
        /^1(3[0-9]|4[01456789]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
      if (phoneReg.test(value)) {
        // 手机号验证通过
        _that.mobileNo_flag = "true";
        callback();
      } else {
        // 手机号验证未通过
        _that.mobileNo_flag = "false";
        callback(new Error("请输入正确的手机号！"));
      }
    };
    // 身份证验证
    const validateIdCard = function (rule, value, callback) {
      // 身份证
      let idcardReg =
        /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
      // 护照
      if (_that.objForm.idType == "17") {
        idcardReg = /^\d{1,}$/;
      }
      if (idcardReg.test(value)) {
        if (_that.clickEventFlag) {
          _that.clickEventFlag = false;
          _that.accountData = [];
          _that.personalInfoData = [];
          _that.$store.commit("SET_PERSONALFLAG", false);
          _that.idCheckTxt = "身份验证未通过";
          _that.idPass = true;
          _that.allFn("cardNo");
        }
        _that.$refs["formPersonal"].clearValidate();
        _that.idNo_flag = "true";
        callback();
      } else {
        _that.idNo_flag = "false";
        callback(new Error("请输入正确的证件号码！"));
      }
    };

    // 客户姓名验证
    const validateAccountName = function (rule, value, callback) {
      if (value === "") {
        _that.accountName_flag = "false";
        callback("请输入客户姓名");
      } else {
        _that.accountName_flag = "true";
        callback();
      }
    };

    // 银行卡号码验证（位数和Luhn算法校验）
    const validateCardNo = function (rule, value, callback) {
      // 判断是否为16或19位纯数字
      if (/^[1-9]\d{15}|[1-9]\d{18}$/.test(value)) {
        console.log("银行卡号验证数字位数通过");
        // //银行卡号验证数字位数通过
        // let nums = value.split('').reverse().map(Number);
        // //校验算法 Luhn算法
        // let sum = nums.reduce((acc, val, i) => {
        //   let v = i % 2 ? val * 2 : val;
        //   return acc + (v > 9 ? v - 9 : v);
        // }, 0);
        // console.log(sum)
        // if(sum % 10 === 0){
        //   //银行卡号码 校验算法Luhn通过
        //   callback();
        // }else{
        //   //银行卡号码 校验算法Luhn未通过
        //   callback(new Error("请输入正确的银行卡号"));
        // }
        _that.cardNo_flag = "true";
        callback();
      } else {
        console.log("银行卡号验证数字位数未通过");
        _that.cardNo_flag = "false";
        callback(new Error("请输入正确的银行卡号！"));
      }
    };

    return {
      iskheck: false, //是否已经客户查询
      userinput: "", //储存进线时候查询的证件
      uid: "",
      // 业务信息列表
      listData: [],
      tableData2222: [
        {
          count: 9,
          customerId: "13312029067",
          expanded: "false",
          detail: [
            { customerNo: "13312029067" },
            { customerNo: "13312029067" },
          ],
        },
      ],
      checkFlag: false,
      // 客户输入信息
      objForm: {},
      optionFormData: {
        emptyBtn: false,
        submitBtn: false,
        menuPosition: "left",
        column: [
          {
            label: "手机号",
            prop: "mobileNo",
            appendClick: () => {
              this.clickEventFlag = true;
              this.$refs["formPersonal"].validateField("mobileNo");
            },
            // 'mock': {
            //   'type': 'cardAccNumber'
            // },
            rules: [
              {
                required: true,
                message: "请输入预留手机号",
                trigger: "blur",
              },
              {
                validator: validatePhone,
                trigger: "blur",
              },
            ],
            style: "width:300px;",
          },
          {
            label: "身份证号",
            prop: "idNo",
            appendClick: () => {
              this.clickEventFlag = true;
              this.$refs["formPersonal"].validateField("idNo");
            },
            // 'mock': {
            //   'type': 'idNum'
            // },
            rules: [
              {
                required: true,
                message: "请输入证件号码",
                trigger: "blur",
              },
              {
                validator: validateIdCard,
                trigger: "blur",
              },
            ],
            style: "width:300px;",
          },
          {
            label: "客户姓名",
            prop: "accountName",
            appendClick: () => {
              this.clickEventFlag = true;
              this.$refs["formPersonal"].validateField("accountName");
            },
            // 'mock': {
            //   'type': 'cardAccNumber'
            // },
            rules: [
              {
                required: true,
                message: "请输入客户姓名",
                trigger: "blur",
              },
              {
                validator: validateAccountName,
                trigger: "blur",
              },
            ],
            style: "width:300px;",
          },
          {
            label: "银行卡号",
            prop: "cardNo",
            appendClick: () => {
              this.clickEventFlag = true;
              this.$refs["formPersonal"].validateField("cardNo");
            },
            // 'mock': {
            //   'type': 'cardAccNumber'
            // },
            rules: [
              {
                required: true,
                message: "请输入银行卡号",
                trigger: "blur",
              },
              {
                validator: validateCardNo,
                trigger: "blur",
              },
            ],
            style: "width:300px",
          },
        ],
      },
      idCheckTxt: "身份验证未通过",
      idPass: true,
      personalInfoData: {},
      defaultCustInfo: {
        custName: "--",
        gender: "--",
        age: "--",
        address: "--",
        mobileNo: "-",
        idNo: "-",
        accountName: "-",
        cardNo: "-",
        idValidity: "--",
        ocpCdVal: "--",
        scdLvlOcpCdVal: "--",
      },
      personalOption: {},
      // 验密结果true
      verificationResult: true,
      cardNo_flag: "false",
      idNo_flag: "false",
      accountName_flag: "false",
      mobileNo_flag: "false",
      flag_smsorpassword: false,
      showAttachDialog: false,
    };
  },
  created() {
    this._setParamsModule();
  },

  mounted() {
    // console.log('router name is ' + this.$route.name)
    const self = this;
    // 验密结果
    window.eventEmitter.$on("EventVerifyResult", (data) => {
      console.log("验密结果：");
      console.log(data.i_verifyflag);
      if (data.i_verifyflag == "01") {
        self.$store.commit("SET_PERSONALFLAG", true);
        self.idCheckTxt = "身份验证通过";
        self.idPass = false;
        self.verificationResult = true;
      } else {
        self.$store.commit("SET_PERSONALFLAG", false);
        self.idCheckTxt = "身份验证未通过";
        self.idPass = true;
        self.verificationResult = false;
      }
    });
    // 振铃进线初始化
    window.eventEmitter.$on("EventCallRecordChange", (data) => {
      // console.log("振铃进线初始化",data);
      // console.log(data);
      self.personalInfoData = self.defaultCustInfo;
      self.$store.commit("SET_PERSONALFLAG", false);
      self.$store.commit("SET_OFFLINESTATUS", false);
      self.$store.commit("SET_PERSONALCHECKFLAG", false);
      self.$store.commit("SET_GLOBALCARDNO", "");
      self.$store.commit("SET_SIYAOSUFLAG", true);
      self.iskheck = false;
      self.idCheckTxt = "身份验证未通过";
      self.idPass = true;
      self.verificationResult = false;
      self.uid = data.uid; //进线手机号
      self.userinput = ""; //还原
      self.$router.push({ name: "personal" }); //回到首页
    });
    // 挂机初始化
    // window.eventEmitter.$on("EventInfoReset", (data) => {
    window.eventEmitter.$on("EventCallReleased", (data) => {
      console.log("电话挂机初始化：");
      // console.log(data);
      // self.personalInfoData = self.defaultCustInfo;
      self.objForm = {};
      self.objForm.idNo = "";
      self.objForm.cardNo = "";
      self.objForm.accountName = "";
      self.objForm.mobileNo = "";
      self.$router.push({ name: "personal" }); //回到首页
      this.$router.push({ name: "personal" }); //回到首页

      this.objForm = {};
      this.objForm.idNo = "";
      this.objForm.cardNo = "";
      this.objForm.accountName = "";
      this.objForm.mobileNo = "";

      self.idCheckTxt = "身份验证未通过";
      self.idPass = true;
      self.iskheck = false;
      self.verificationResult = false;
      self.$store.commit("SET_PERSONALCHECKFLAG", false);
      self.$store.commit("SET_OFFLINESTATUS", true);
      self.$store.commit("SET_SIYAOSUFLAG", false);
      self.$store.commit("SET_GLOBALCARDNO", "");
      self.userinput = ""; //还原
    });
    // 文本进线初始化
    window.eventEmitter.$on("EventChatRecordChange", (data) => {
      console.log("文本进线初始化：", data);
      self.uid = data.uid; //进线手机号
      self.verificationResult = true; //四要素
      self.$store.commit("SET_OFFLINESTATUS", false);
      self.$store.commit("SET_SIYAOSUFLAG", true);
      self.userinput = ""; //还原
      self.idPass = true;
      self.iskheck = false;
      self.$router.push({ name: "personal" }); //回到首页

      // console.log(
      //   "文本进线修改离线状态",
      //   self.$store.getters.GET_OFFLINESTATUS
      // );
    });
    //文本挂机
    window.eventEmitter.$on("EventCallEnd", (data) => {
      console.log("文本挂机");
      self.objForm = {};
      self.objForm.idNo = "";
      self.objForm.cardNo = "";
      self.objForm.accountName = "";
      self.objForm.mobileNo = "";
      self.$router.push({ name: "personal" }); //回到首页
      this.$router.push({ name: "personal" }); //回到首页

      this.objForm = {};
      this.objForm.idNo = "";
      this.objForm.cardNo = "";
      this.objForm.accountName = "";
      this.objForm.mobileNo = "";

      console.log("当前输入框值为", self.objForm, this.objForm);

      self.idCheckTxt = "身份验证未通过";
      self.idPass = true;
      // self.verificationResult = false;
      self.$store.commit("SET_PERSONALCHECKFLAG", false);
      self.$store.commit("SET_OFFLINESTATUS", true);
      self.$store.commit("SET_SIYAOSUFLAG", false);
      self.$store.commit("SET_GLOBALCARDNO", "");
      self.userinput = ""; //还原
      self.iskheck = false;
    });

    // window.eventEmitter.$on("AgentStatusChanged", (data) => {
    //   console.log("文本进线初始化：");
    //   self.uid = data.uid; //进线手机号
    //   self.verificationResult = true;  //四要素
    // });
  },
  methods: {
    // 数组排序
    sortArr(arr, str) {
      const _arr = [];
      let _t = [];
      let _tmp;
      // 按时间排序 最新的在前面
      arr = arr.sort(function (a, b) {
        return Date.parse(b.createTime) - Date.parse(a.createTime);
      });
      // 按渠道名相同的排序
      arr = arr.sort(function (a, b) {
        var s = a[str];
        var t = b[str];
        return s < t ? -1 : 1;
      });
      if (arr.length) {
        _tmp = arr[0][str];
      }
      for (var i in arr) {
        if (arr[i][str] === _tmp) {
          _t.push(arr[i]);
        } else {
          _tmp = arr[i][str];
          _arr.push(_t);
          _t = [arr[i]];
        }
      }
      _arr.push(_t);
      return _arr;
    },
    // 统计次数
    getTimes(arr, type) {
      const obj = {};
      // 单笔单批
      if (type == "1") {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].risCode == "A") {
            if (obj[arr[i].channelName]) {
              obj[arr[i].channelName]++;
            } else {
              obj[arr[i].channelName] = 1;
            }
          }
        }
        // 其它
      } else if (type == "0") {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].isCallStatus == "1" && arr[i].risCode == "A") {
            if (obj[arr[i].channelName]) {
              obj[arr[i].channelName]++;
            } else {
              obj[arr[i].channelName] = 1;
            }
          }
        }
      }
      const newArr = [];
      for (const j in obj) {
        newArr.push(`${j} (${obj[j]}次)`);
      }
      const str = newArr.toString();
      return str;
    },
    // 客户信息查询
    customerInquiry() {
      const phoneRegex = /^1[3456789]\d{9}$/;
      const idCardRegex =
        /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;

      //正则校验是否为手机号与身份证
      if (
        !phoneRegex.test(this.objForm.mobileNo) ||
        !idCardRegex.test(this.objForm.idNo)
      ) {
        return window.globalUiKit.notify("提示", "手机或身份证不合规", "error");
      }

      //重新查询客户信息 清空验密状态
      this.$store.commit("SET_PERSONALFLAG", false);
      this.idCheckTxt = "身份验证未通过";
      this.idPass = true;
      this.flag_smsorpassword = true;
      this.verificationResult = false;

      // this.iskheck = true;
      sessionStorage.setItem("personalInfoData", JSON.stringify({})); // 清空客户信息缓存

      if (this.userinput == "") {
        this.userinput = this.objForm.idNo;
      }

      //客户信息清空
      this.personalInfoData = {};
      /** 查询客户信息  */
      // if (this.$store.getters.GET_OFFLINESTATUS) {
      //   return window.globalUiKit.notify(
      //     "提示",
      //     "离线状态不能查询客户信息！",
      //     "error"
      //   );
      // }

      console.log("客户信息查询", this.objForm);
      queryCustomerLaonData(this.objForm)
        .then((res) => {
          console.log("客户信息查询返回==", res);
          if (res.data.code == "0000") {
            // this.personalInfoData = res.data.data;

            var testdata = res.data.data;

            this.personalInfoData = testdata;

            //手动输入的手机号与接口返回的对不上，标红
            if (this.objForm.mobileNo != this.personalInfoData.mobileNo) {
              this.personalInfoData.isRed = true;
            }

            // const creditList = res.data.data.creditList;
            const creditList = this.personalInfoData.contrDetailList;

            //传递客户信息给工单 事件（2024-05-08添加，工单要取这里的数据）
            var msgData = {};
            msgData.accountName = this.personalInfoData.custName; //客户姓名
            msgData.idNo = this.personalInfoData.idNo; //身份证号
            msgData.mobileNo = this.personalInfoData.mobileNo; //手机号
            msgData.uid = this.uid; //进线手机号
            var message = {
              event: "EventCustomerQuery",
              data: msgData,
            };
            let etsFrame = document.getElementById("ets-create-frame");
            etsFrame.contentWindow.postMessage(message, "*");

            // 给 四要素—客户姓名 赋值
            // this.objForm.accountName = res.data.data.custName;
            this.objForm.accountName = this.personalInfoData.custName;
            this.accountName_flag = "true";

            creditList.forEach((item) => {
              // 渠道名称
              item.channelName = item.productName;
              // 客户状态
              if (item.approveType == "C") {
                item.approveType = "授信";
              } else if (item.approveType == "V") {
                item.approveType = "用信";
              }
            });
            // 根据渠道来源分类
            const newCreditList = this.sortArr(creditList, "channelName");
            // 统计客户状态
            const idValidity = [];
            console.log("newCreditList", newCreditList);
            newCreditList.forEach((item) => {
              const str = `${item[0].channelName}(${item[0].approveType})`;
              if (item[0].channelName) {
                idValidity.push(str);
              }
            });
            this.personalInfoData.idValidity = idValidity.toString();
            // 授信渠道
            // 判断产品类别 isSingleApprove  0-否 1-是
            // 是否调用风控 isCallStatus     0-否 1-是
            // 单笔单批 risCode==A 授信次数+1 非单笔单批的 risCode==A  isCallStatus==1 授信次数+1
            const _newCreditList = this.sortArr(creditList, "isSingleApprove");
            const ocpCdVal = [];
            _newCreditList.forEach((item, index) => {
              if (this.getTimes(item, index)) {
                ocpCdVal.push(this.getTimes(item, index));
              }
            });
            if (ocpCdVal && ocpCdVal.length > 0) {
              this.personalInfoData.ocpCdVal = ocpCdVal.toString();
            } else {
              this.personalInfoData.ocpCdVal = "--";
            }
            // 用信状态
            // risCode ==A 次数+1
            // const scdLvlOcpCdVal = [];
            // if (this.getTimes(creditList, 1)) {
            //   scdLvlOcpCdVal.push(this.getTimes(creditList, 1));
            // }
            // if (scdLvlOcpCdVal && scdLvlOcpCdVal.length > 0) {
            //   this.personalInfoData.scdLvlOcpCdVal = scdLvlOcpCdVal.toString();
            // } else {
            //   this.personalInfoData.scdLvlOcpCdVal = "--";
            // }
            //合同信息存session
            sessionStorage.setItem(
              "personalInfoData",
              JSON.stringify(this.personalInfoData)
            );
          } else {
            // 无此客户信息恢复默认
            this.personalInfoData = this.defaultCustInfo;
            window.globalUiKit.notify("提示", "查询无客户信息！", "info");
            // 清除验证标识
            if (!this.$store.getters.GET_PERSONALFLAG) {
              this.$store.commit("SET_PERSONALFLAG", false);
              this.idCheckTxt = "身份验证未通过";
              this.idPass = true;
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 客户信息查询
    siyaosucustomerInquiry() {
      //重新查询客户信息 清空验密状态
      // this.$store.commit("SET_PERSONALFLAG", false);
      // this.idCheckTxt = "身份验证未通过";
      // this.idPass = true;
      // this.flag_smsorpassword = true;
      // this.verificationResult = false;

      // this.iskheck = true;
      sessionStorage.setItem("personalInfoData", JSON.stringify({})); // 清空客户信息缓存

      if (this.userinput == "") {
        this.userinput = this.objForm.idNo;
      }

      //客户信息清空
      this.personalInfoData = {};

      /** 查询客户信息  */

      // if (this.$store.getters.GET_OFFLINESTATUS) {
      //   return window.globalUiKit.notify(
      //     "提示",
      //     "离线状态不能查询客户信息！",
      //     "error"
      //   );
      // }
      var params = {
        idNo: this.objForm.idNo,
      };

      // console.log("四要素成功后查客户信息查询", params);
      queryCustomerLaonData(params)
        .then((res) => {
          console.log("四要素成功后客户信息查询返回==", res);
          if (res.data.code == "0000") {
            // this.personalInfoData = res.data.data;

            var testdata = res.data.data;
            this.personalInfoData = testdata;

            //手动输入的手机号与接口返回的对不上，标红
            if (this.objForm.mobileNo != this.personalInfoData.mobileNo) {
              this.personalInfoData.isRed = true;
            }

            // const creditList = res.data.data.creditList;
            const creditList = this.personalInfoData.contrDetailList;

            //传递客户信息给工单 事件（2024-05-08添加，工单要取这里的数据）
            var msgData = {};
            msgData.accountName = this.personalInfoData.custName; //客户姓名
            msgData.idNo = this.personalInfoData.idNo; //身份证号
            msgData.mobileNo = this.personalInfoData.mobileNo; //手机号
            msgData.uid = this.uid; //进线手机号
            var message = {
              event: "EventCustomerQuery",
              data: msgData,
            };
            let etsFrame = document.getElementById("ets-create-frame");
            etsFrame.contentWindow.postMessage(message, "*");

            // 给 四要素—客户姓名 赋值
            // this.objForm.accountName = res.data.data.custName;
            // this.objForm.accountName = this.personalInfoData.custName;
            // this.accountName_flag = "true";

            creditList.forEach((item) => {
              // 渠道名称
              item.channelName = item.productName;
              // 客户状态
              if (item.approveType == "C") {
                item.approveType = "授信";
              } else if (item.approveType == "V") {
                item.approveType = "用信";
              }
            });
            // 根据渠道来源分类
            const newCreditList = this.sortArr(creditList, "channelName");
            // 统计客户状态
            const idValidity = [];
            console.log("newCreditList", newCreditList);
            newCreditList.forEach((item) => {
              const str = `${item[0].channelName}(${item[0].approveType})`;
              if (item[0].channelName) {
                idValidity.push(str);
              }
            });
            this.personalInfoData.idValidity = idValidity.toString();
            // 授信渠道
            // 判断产品类别 isSingleApprove  0-否 1-是
            // 是否调用风控 isCallStatus     0-否 1-是
            // 单笔单批 risCode==A 授信次数+1 非单笔单批的 risCode==A  isCallStatus==1 授信次数+1
            const _newCreditList = this.sortArr(creditList, "isSingleApprove");
            const ocpCdVal = [];
            _newCreditList.forEach((item, index) => {
              if (this.getTimes(item, index)) {
                ocpCdVal.push(this.getTimes(item, index));
              }
            });
            if (ocpCdVal && ocpCdVal.length > 0) {
              this.personalInfoData.ocpCdVal = ocpCdVal.toString();
            } else {
              this.personalInfoData.ocpCdVal = "--";
            }
            // 用信状态
            // risCode ==A 次数+1
            // const scdLvlOcpCdVal = [];
            // if (this.getTimes(creditList, 1)) {
            //   scdLvlOcpCdVal.push(this.getTimes(creditList, 1));
            // }
            // if (scdLvlOcpCdVal && scdLvlOcpCdVal.length > 0) {
            //   this.personalInfoData.scdLvlOcpCdVal = scdLvlOcpCdVal.toString();
            // } else {
            //   this.personalInfoData.scdLvlOcpCdVal = "--";
            // }
            //合同信息存session
            sessionStorage.setItem(
              "personalInfoData",
              JSON.stringify(this.personalInfoData)
            );
          } else {
            // 无此客户信息恢复默认
            this.personalInfoData = this.defaultCustInfo;
            window.globalUiKit.notify("提示", "查询无客户信息！", "info");
            // 清除验证标识
            if (!this.$store.getters.GET_PERSONALFLAG) {
              this.$store.commit("SET_PERSONALFLAG", false);
              this.idCheckTxt = "身份验证未通过";
              this.idPass = true;
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 跳转合同列表——>跳转router路由
    goCreditList(name) {
      // console.log("跳转2", name);
      if (name == "customerInfoUpdateTable") {
        return this.$router.push({ name });
      }

      // 验证通过后才可以跳转
      if (this.verificationResult) {
        //   console.log("-------");
        if (
          name === "transactionFlowQuery" ||
          name === "customeBuss" ||
          name === "loanData"
        ) {
          this.$router.push({ name });
          // if(!this.flag_smsorpassword){
          //   this.$router.push({ name })
          // }else{
          //   window.globalUiKit.notify('提示', '请先进行动态密码验证或短信验证', 'info')
          // }
        } else {
          this.$router.push({ name });
        }

        // if(name==='repaymentOffline'){
        //   this.$router.push({
        //     name:'repaymentOffline',
        //     query: {
        //       target: '_blank'
        //     }
        //   })
        //   window.open('http://localhost:8080/#/personal/repaymentOffline','_blank')

        //   let url = this.$router.resolve({
        //     name:'repaymentOffline'
        //   })
        //   window.open(url.href,'_blank')

        // }else{
        //   this.$router.push({name})
        // }
      } else {
        window.globalUiKit.notify("提示", "请先进行验密操作！", "error");
        this.idCheckTxt = "身份验证未通过";
      }
    },
    // 模块参数化配置
    _setParamsModule() {
      this.personalOption = window.personalOptions.moduleOption.personalOption;
      this.listData = window.personalOptions.routerQuery;
    },

    // 搜索框查询
    searchSubmitForm() {
      this.$message.success("当前数据" + JSON.stringify(this.objForm));
    },
    // 验密
    verificationFn(code) {
      var self = this;
      // console.log("this==", this);
      // console.log("self===", self);
      //取消self  全部使用this尝试。 this.$message.success("已发送短信验证"); 使用this

      if (!window.Settings.verifySwitch) {
        if (this.$store.getters.GET_OFFLINESTATUS) {
          window.globalUiKit.notify("提示", "离线状态不能验密！", "error");
          return;
        }
        // 如果客户信息存在才可以验证
        if (!this.personalInfoData) {
          window.globalUiKit.notify("提示", "客户信息不存在！", "error");
          return;
        }
      } else {
        this.$store.commit("SET_PERSONALFLAG", true);
      }
      // 判断是哪种验证方式
      window.globalUiKit.confirm(
        "提示",
        "是否要进行电话验密操作?",
        function () {
          var this_ = self;
          // console.log("this_==", this_);
          // console.log("this_.personalInfoData=", this_.personalInfoData);
          // 密码验证
          if (code == "0") {
            var userdata = {
              // 私有部分，根据不同验证类型组合
              p_verifytype: "01", // 验密类型  01：电话验密  02：短信验密
              p_cert_type: "01", // 介质类型   01：进线手机号
              p_cert_num: this_.personalInfoData.mobileNo || "", // 介质号码
              p_accno: "", // 对公客户号
              p_oper_id: "", // 对公操作员ID
              p_pass_type: "01", // 密码类型
              p_pass_operate: "01", // 交易密码操作
              p_biz: "00", // 业务操作
              // 公共部分
              r_function: "singletransfer",
              r_flag: "3",
              con_flag: "1",
            };
            globalUserData.verifyPass(userdata); // 发起验密
          } else {
            console.log("准备短信验证");
            // 短信验证
            // 发送短信验证
            const data = { mobileNo: this_.personalInfoData.mobileNo };
            sendCode(data).then((res) => {
              if (res.data.code == "200") {
                // console.log("已发送短信验证");
                this_.$message.success("已发送短信验证");
                var userdata = {
                  // 私有部分，根据不同验证类型组合
                  p_verifytype: "02", // 验密类型  01：电话验密  02：短信验密
                  p_cert_type: "01", // 介质类型   01：进线手机号
                  p_cert_num: this_.personalInfoData.mobileNo || "", // 介质号码
                  p_ccsCode: res.data.data.ccsCode, // 短信流水号
                  p_accno: "", // 对公客户号
                  p_oper_id: "", // 对公操作员ID
                  p_pass_type: "01", // 密码类型
                  p_pass_operate: "01", // 交易密码操作
                  p_biz: "00", // 业务操作
                  // 公共部分
                  r_function: "singletransfer",
                  r_flag: "3",
                  con_flag: "1",
                };
                globalUserData.verifyPass(userdata); // 发起验密
              }
            });
          }
          if (window.Settings.verifySuccessSwitch) {
            this.$store.commit("SET_PERSONALFLAG", true);
            this.idCheckTxt = "身份验证通过";
            this.idPass = false;
            this.flag_smsorpassword = true;
          }
        }
      );
    },

    // 四要素核身
    fourelementsProcess() {
      // if (!this.iskheck) {
      //   return window.globalUiKit.notify("提示", "请先查询客户信息", "error");
      // }
      if (!this.$store.getters.GET_SIYAOSUFLAG) {
        window.globalUiKit.notify("提示", "离线状态不能验证四要素！", "error");
        return;
      }
      const phoneRegex = /^1[3456789]\d{9}$/;
      const idCardRegex =
        /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
      const nameRegex = /^[\u4e00-\u9fa5]{2,6}$/;
      const bankCardRegex = /^\d{16,19}$/;

      if (
        !phoneRegex.test(this.objForm.mobileNo) &&
        !idCardRegex.test(this.objForm.idNo) &&
        !nameRegex.test(this.objForm.accountName) &&
        !bankCardRegex.test(this.objForm.cardNo)
      ) {
        return window.globalUiKit.notify(
          "提示",
          "请检查输入信息是否完整",
          "error"
        );
      }

      // console.log("第一次查询的证件为", this.userinput);
      // console.log("当前查询证件为", this.objForm.idNo);

      // if (this.userinput != this.objForm.idNo && this.userinput !== "") {
      //   console.log("当前查询身份证与第一次不相符，四要素验证失效");
      //   this.verificationResult = false; // 验密结果（四要素核身通过可以办全部业务，所以这里标记true了）
      //   this.idCheckTxt = "身份验证未通过"; // 身份验证未通过
      //   this.idPass = true;
      // }

      // console.log("开始四要素核身流程--------------");
      const self = this;

      // console.log(this.objForm);
      // 判断四要素是否为空，必须都不为空
      if (
        this.objForm.idNo != "" &&
        this.objForm.cardNo != "" &&
        this.objForm.accountName != "" &&
        this.objForm.mobileNo != ""
      ) {
        // 校验四要素是否全部符合格式
        if (this.cardNo_flag === "false") {
          console.log("银行卡号格式错误，请重新填写");
          return;
        }

        if (this.idNo_flag === "false") {
          console.log("身份证号格式错误，请重新填写");
          return;
        }

        if (this.accountName_flag === "false") {
          console.log("客户姓名格式错误，请重新填写");
          return;
        }

        if (this.mobileNo_flag === "false") {
          console.log("手机号格式错误，请重新填写");
          return;
        }

        // console.log(JSON.stringify(self.personalInfoData));
        // console.log(self.personalInfoData.length === 0);
        // 如果客户信息存在才可以验证

        if (JSON.stringify(self.personalInfoData) === "{}") {
          window.globalUiKit.notify("提示", "客户信息不存在！", "error");
          return;
        } else {
          console.log("四要素接口入参", self.objForm);

          // 将四要素传递给后端接口，获取返回值判断是否验证成功
          axios
            .post(
              window.CONFIG.tradingUrl + "/FourelementsProcess/ProcessBaofu",
              self.objForm
            )
            .then((res) => {
              // console.log("四要素核身返回结果：");
              // console.log(res);
              if (res.data.status == "true") {
                console.log("四要素核身成功");
                // 返回信息处理：
                // 四要素核身通过，可以办理所有业务
                self.$store.commit("SET_PERSONALFLAG", true);
                self.idCheckTxt = "身份验证通过";
                self.idPass = false;
                self.verificationResult = true; // 验密结果（四要素核身通过可以办全部业务，所以这里标记true了）
                //调查客户信息
                self.siyaosucustomerInquiry();
                self.iskheck = false;
              } else {
                console.log(
                  "四要素核身未成功",
                  this.$store.getters.GET_PERSONALFLAG
                );
                // this.personalInfoData = this.defaultCustInfo;
                // 四要素核身未通过，需进行密码验证/短信验证（二级核身）
                // if (!this.$store.getters.GET_PERSONALFLAG) {
                this.$store.commit("SET_PERSONALFLAG", false);
                this.idCheckTxt = "身份验证未通过";
                this.idPass = true;
                // self.iskheck = false
                self.flag_smsorpassword = true;
                self.verificationResult = false;
                //客户信息清空
                self.personalInfoData = [];
                //客户信息存进sessionStorage
                sessionStorage.setItem(
                  "personalInfoData",
                  JSON.stringify(this.personalInfoData)
                );
                // }
              }
              console.log("四要素核身流程结束--------------");
            });
        }
      } else {
        alert("请检查手机号、身份证号、客户姓名、银行卡号是否填写");
      }
    },

    // 跳转线下还款页面
    // ToRepaymentOffline(){
    //   let url = this.$router.resolve({
    //     path:'/repaymentOffline'
    //   })
    //   window.open(url.href,'_blank')
    // },

    // 按钮搜索条件，请求方法集合
    allFn() {
      // 离线状态不能操作
      if (this.$store.getters.GET_OFFLINESTATUS) {
        window.globalUiKit.notify("提示", "离线状态不能查询！", "error");
        return;
      }
      this.customerInquiry();
    },
  },
  // 路由拦截
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      console.log("personal bank no is: " + vm.personalBankNo);
      if (vm.personalBankNo) {
        sessionStorage.setItem("bankNo", vm.personalBankNo);
      } else {
        sessionStorage.setItem("bankNo", "");
      }
    });
  },
};
</script>
<style scoped>
.custInfo .el-col span,
.cardAndAccInfo .el-col span {
  line-height: 34px;
}

.bankNameSelect .el-select .el-input.is-focus .el-input__inner {
  border-color: #b50029 !important;
}

/*子模块区域*/
.inlineStyle {
  width: 100px;
  display: inline-block;
  text-align: center;
}

.inlineStyle span {
  text-align: center;
  display: block;
}

.sonArea img {
  width: 70px;
  height: 70px;
}

.el-dialog tr > th.el-table_1_column_1 > .cell {
  display: none;
}

/*超出省略*/
.wordEllipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  white-space: nowrap;
}

.bankContainer .el-form-item {
  margin-bottom: 6px;
}

.bankContainer ul li {
  float: none !important;
  text-align: left !important;
}

.topHeaderSearch span {
  height: 40px;
  line-height: 40px;
}

.searchInputStyle {
  color: #606266;
  font-weight: 700;
  line-height: 34px;
}

.verificationTips {
  width: 100%;
  height: 1px;
  text-align: right;
  position: relative;
}

.verificationTips span {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 99;
}

.elTableHeader {
  background-color: aqua;
  color: black;
}
</style>
